#include "UGController.h"

namespace ugame {
    UGController::UGController() {
        this->eventNotifier = UGApplication::getInstance()->getSharedEventNotifier();
        CC_SAFE_RETAIN(this->eventNotifier);
    }
    
    UGController::~UGController() {
        CC_SAFE_RELEASE(this->eventNotifier);
    }
    
    void UGController::registerHandler(UGEventHandler* handler) {
        this->eventNotifier->registerHandler(handler);
    }
    
    void UGController::registerHandler(int order, Ref* handlerObj, UGHandlerFunc handlerFunc) {
        UGEventHandler* handler = UGDefaultEventHandler::create(order, handlerObj, handlerFunc);
        this->eventNotifier->registerHandler(handler);
    }
    
    void UGController::registerHandlerByEventType(int eventType, int order, Ref* handlerObj, UGHandlerFunc handlerFunc) {
        UGEventHandler* handler = UGDefaultEventHandler::createByEventType(eventType, order, handlerObj, handlerFunc);
        this->eventNotifier->registerHandler(handler);
    }
    
    void UGController::registerHandlerByEventId(int eventId, int order, Ref* handlerObj, UGHandlerFunc handlerFunc) {
        UGEventHandler* handler = UGDefaultEventHandler::createByEventId(eventId, order, handlerObj, handlerFunc);
        this->eventNotifier->registerHandler(handler);
    }

	void UGController::notify(UGEvent* event) {
        this->getEventNotifier()->notifyEvent(event);
    }
    
    void UGController::notify(int eventId, int eventType, Ref* sender, float delayTime, void* eventArg) {
        UGEvent* event = UGDefaultEvent::create(eventId, eventType, sender, delayTime, eventArg);
        this->getEventNotifier()->notifyEvent(event);
    }
}